<template>
  <view class="container">
    <!-- 搜索栏 -->
    <view class="search-bar">
      <input class="search-input" type="text" placeholder="输入需要搜索的内容" />
     <image 
         class="search-icon" 
         src="/static/car_wash/搜索@3x.png"  
         mode="widthFix" 
         style="width: 20px; height: 20px;"></image>
</view>
    <!-- 历史记录（横向滚动） -->
    <view class="history-title">历史记录：</view>
    <scroll-view class="history-scroll" scroll-x="true" white-space="nowrap">
      <view class="history-item" v-for="(item, index) in historyRecords" :key="index">
        {{ item }}
      </view>
    </scroll-view>

    <!-- 店铺列表 -->
    <view class="shops-list">
      <view 
          class="shop-item" 
          v-for="(shop, index) in shops" 
          :key="shop.id"  
          @click="goToDetail(shop)"  
        >
        <!-- 店铺图片 -->
        <image class="shop-image" :src="shop.image" mode="widthFix"></image>
        <!-- 店铺信息（名称、评分、营业时间等） -->
        <view class="shop-info">
          <view class="shop-name">{{ shop.name }}</view>
          <view class="shop-rating">
            <uni-icons type="star-filled" color="#FFCC33"></uni-icons>
            <uni-icons type="star-filled" color="#FFCC33"></uni-icons>
            <uni-icons type="star-filled" color="#FFCC33"></uni-icons>
            <uni-icons type="star-filled" color="#FFCC33"></uni-icons>
            <text>{{ shop.score }}分</text>
            <text> 销量：{{ shop.sales }}</text>
          </view>
          <view class="shop-time">{{ shop.time }}</view>
          <view class="shop-address">{{ shop.address }}</view>
        </view>
        <!-- 距离 -->
        <view class="shop-distance">{{ shop.distance }}</view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      // 历史记录数据（模拟）
      historyRecords: [
        "飞飞汽车美容店", "飞飞汽修美容店", "飞飞汽车美容店",
        "飞飞汽修美容店", "飞飞汽修美容店", "汽车美容店", "汽修美容店"
      ],
      // 店铺列表数据（模拟，实际可从接口获取）
      shops: [
        {
			id:1,
          name: "车百事汽车生活馆",
          distance: "556m",
          score: 4,
          sales: 556,
          time: "营业时间：周一至周五 早上8:00-晚上22:00",
          address: "山阳区人民路与解放路交叉口",
          image: "/static/car_shop.jpg" // 需在static目录放店铺图片
        },
        {
			id:2,
          name: "车百事汽车生活馆",
          distance: "556m",
          score: 4,
          sales: 556,
          time: "营业时间：周一至周五 早上8:00-晚上22:00",
          address: "山阳区人民路与解放路交叉口",
          image: "/static/car_shop.jpg"
        },
        {
			id:3,
          name: "车百事汽车生活馆",
          distance: "5.6km",
          score: 4,
          sales: 556,
          time: "营业时间：周一至周五 早上8:00-晚上22:00",
          address: "山阳区人民路与解放路交叉口",
          image: "/static/car_shop.jpg"
        },
        {
			id:4,
          name: "车百事汽车生活馆",
          distance: "556m",
          score: 4,
          sales: 556,
          time: "营业时间：周一至周五 早上8:00-晚上22:00",
          address: "山阳区人民路与解放路交叉口",
          image: "/static/car_shop.jpg"
        },
        {
			id:5,
          name: "车百事汽车生活馆",
          distance: "556m",
          score: 4,
          sales: 556,
          time: "营业时间：周一至周五 早上8:00-晚上22:00",
          address: "山阳区人民路与解放路交叉口",
          image: "/static/car_shop.jpg"
        }
      ]
    };
  },
  methods: {
      // 新增：跳转店铺详情页的方法
      goToDetail(shop) {
        // 1. 检查详情页路径是否正确（确保和目标页面路径一致）
        const detailPath = "/pages/car_wash/details/details";
        // 2. 传递店铺ID作为参数（用模板字符串拼接，参数名建议用id）
        const url = `${detailPath}?id=${shop.id}`;
        
        // 3. 执行跳转
        uni.navigateTo({
          url: url,
          success: () => {
            console.log("跳转详情页成功，店铺ID：", shop.id);
          },
          fail: (err) => {
            console.error("跳转详情页失败：", err);
            // 跳转失败时提示用户
            uni.showToast({
              title: "详情页跳转失败",
              icon: "none",
              duration: 1500
            });
          }
        });
      }
    }
};
</script>

<style scoped>
/* 页面整体容器 */
.container {
  padding: 10px;
  background-color: #fff;
}

/* 搜索栏样式 */
.search-bar {
  display: flex;
  align-items: center;
  border: 1px solid #eee;
  border-radius: 5px;
  padding: 5px 10px;
  margin-bottom: 15px;
}
.search-input {
  flex: 1;
  height: 30px;
  font-size: 14px;
}
.search-icon {
  color: #999;
}

/* 历史记录样式 */
.history-title {
  font-size: 14px;
  color: #333;
  margin-bottom: 5px;
}
.history-scroll {
 height: auto; /* 从30px改为auto，自适应内容高度 */
   margin-bottom: 15px;
   line-height: 28px; /* 可选：增加行高，优化文字垂直居中 */
}
.history-item {
  display: inline-block;
  padding: 0 8px;
  font-size: 13px;
  color: #666;
}

/* 店铺列表样式 */
.shops-list {
  display: flex;
  flex-direction: column;
  gap: 15px;
}
.shop-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}
.shop-image {
  width: 120px;
  height: auto;
  border-radius: 4px;
}
.shop-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.shop-name {
  font-size: 16px;
  font-weight: bold;
  color: #333;
}
.shop-rating {
  font-size: 12px;
  color: #666;
  display: flex;
  align-items: center;
  gap: 3px;
}
.shop-time,
.shop-address {
  font-size: 12px;
  color: #999;
}
.shop-distance {
  font-size: 14px;
  color: #555;
}
</style>